// pages/elderly/help/help.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputShowed: false,
    inputVal: "",
    show_select_line: false,
    shows: false, //控制下拉列表的显示隐藏，false隐藏、true显示
    selectDatas: null, //下拉列表的数据
    indexs: 0, //选择的下拉列 表下标,
    userid: null,
    myList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  selectTaps() {
    this.setData({
      shows: !this.data.shows,
    });
  },
    // 点击下拉列表
    optionTaps(e) {
      let Indexs = e.currentTarget.dataset.index; //获取点击的下拉列表的下标
      this.setData({
        indexs: Indexs,
        shows: !this.data.shows
      });
      // console.log(this.data.indexs)
      var all_activities_list = this.data.activitiesList
      var v_activitiesList = []
      // console.log('执行到这')
      if(this.data.activityType==1){
        switch (Indexs){
          case 0:
            this.setData({
              visible_activitiesList: this.data.activitiesList
            })
            break 
          case 1:
            for(var i=0; i<all_activities_list.length; i++){
              // console.log(all_posts_list[i])
              if(all_activities_list[i].isOverdue==0){
                v_activitiesList.push(all_activities_list[i])
              }
            }
            this.setData({
              visible_activitiesList: v_activitiesList
            })
            break
          case 2:
            for(var i=0; i<all_activities_list.length; i++){
              if(all_activities_list[i].isOverdue==2){
                v_activitiesList.push(all_activities_list[i])
              }
            }
            this.setData({
              visible_activitiesList: v_activitiesList
            })
            break
          default:
            console.log('select option index error：', Indexs)
        }
      }
      else{
        switch (Indexs){
          case 0:
            this.setData({
              visible_activitiesList: this.data.activitiesList
            })
            break 
          case 1:
            for(var i=0; i<all_activities_list.length; i++){
              // console.log(all_posts_list[i])
              if(all_activities_list[i].isOverdue==0){
                v_activitiesList.push(all_activities_list[i])
              }
            }
            this.setData({
              visible_activitiesList: v_activitiesList
            })
            break
          case 2:
            for(var i=0; i<all_activities_list.length; i++){
              // console.log(all_posts_list[i])
              if(all_activities_list[i].isOverdue==1){
                v_activitiesList.push(all_activities_list[i])
              }
            }
            this.setData({
              visible_activitiesList: v_activitiesList
            })
            break
          case 3:
            for(var i=0; i<all_activities_list.length; i++){
              // console.log(all_posts_list[i])
              if(all_activities_list[i].isOverdue==2){
                v_activitiesListt.push(all_activities_list[i])
              }
            }
            this.setData({
              visible_activitiesList: v_activitiesList
            })
            break
         
          default:
            console.log('select option index error：', Indexs)
        }
      }
    },
  onLoad: function (options) {
    this.setData({
      userid:app.globalData.userInfo.userId
    })
    var type = options.activityType
    if(type==-1){
      this.getMyActivity()
    }
    if(type==3 || type ==4){
      this.getHuzhiActivity(type)
    }
  },
  getHuzhiActivity(theme){
    var data = {
      theme: theme
    }
    app.sendPostRequest("/heart/selectList", data, (res)=>{
      this.setData({
        myList: res.rows
      })
    },(res)=>{
      console.log(res)
    })
  },
  getMyActivity(){
    var data = {
      initiatorid: this.data.userid
    }
    app.sendPostRequest("/heart/selectList", data, (res)=>{
      this.setData({
        myList: res.rows
      })
    },(res)=>{
      console.log(res)
    })
  },
  showInput: function () {
    this.setData({
        inputShowed: true
    });
  },
  hideInput: function () {
    var v_activitiesList= this.data.activitiesList
    this.setData({
        inputVal: "",
        inputShowed: false,
        visible_activitiesList: v_activitiesList
    });
  },
  clearInput: function () {
    this.setData({
        inputVal: ""
    });
  },
  inputTyping: function (e) {
      this.setData({
          inputVal: e.detail.value
      });
  },
    // 标题关键字搜索
  search: function (e){
    // 搜索字段
    var searchtext = this.data.inputVal
    var activitiesList = this.data.activitiesList
    var v_activitiesList = []
    for(var i=0; i<activitiesList.length; i++){
      var temp = activitiesList[i].title.indexOf(searchtext)
      if(temp!=-1){
        v_activitiesList.push(activitiesList[i])
      }
    }
    this.setData({
      visible_activitiesList: v_activitiesList
    })
  },

  onBriefPostTap: function(e){
    wx.navigateTo({
      url: '../activityDetail/activityDetail?activityId=' + e.currentTarget.dataset.activity_id,
    })
  },
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})